// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
import Vue from 'vue'
import App from './App'
// 引入vuex
import store from './store/store'
import router from './router'
// 引入element-ui
import ElementUI from 'element-ui'
import 'element-ui/lib/theme-chalk/index.css'
// 引入公共样式index.scss文件
import '@/styles/index.scss'

import {checkRootLogin} from '@/api'

Vue.config.productionTip = false
// 使用element-ui
Vue.use(ElementUI)

// 导航守卫
// 调用接口，判断用户是否登录
checkRootLogin().then(res => {
  router.beforeEach((to, from, next) => {
    // console.log(res)
    // console.log(to)
    if (res.success || to.path === { path: 'login' }) {
      next()
    } else {
      router.push({ path: 'login' })
    }
  })
})

/* eslint-disable no-new */
new Vue({
  el: '#app',
  router,
  store,
  components: {
    App
  },
  template: '<App/>'
})
